<script>
import { isObject, isString } from 'is-type-data';

const ss = (data,template) => {
  if(isString(data)) {
    return template.replace(/\${\w+}/g,data)
  }
  if(isObject(data)) {
    let str = template;
    for(let field of Object.keys(data)) {
      const regExp = new RegExp("\\${" +field+ "}", "g");
       str = str.replace(regExp,data[field])
    }
     return str
  }
}
export default {
  name: "AegleSpan",
  props: {
    data: {
      type: [Number, String, Object],
      default: "",
    },
    template: String,
    config: {
      type: Object,
      default: null,
    },
  },
  render() {
    if (this.config) {
      const value = ss(this.data,this.template);
      

      return <span {...this.config.props}>{value}</span>;
    }
  },
};
</script>